package com.qiguliuxing.dts.job.config;

import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.lite.spring.api.SpringJobScheduler;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import com.qiguliuxing.dts.job.base.LiteJobDefinition;
import com.qiguliuxing.dts.job.listener.JobListener;
import com.qiguliuxing.dts.job.task.CloseOrderCommentJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 关闭超期未评论订单的执行配置
 * @author qiguliuxing
 * @since 1.0.0
 */
@Configuration
public class CloseOrderCommentJobConfig {

    @Value("${close.order.comment.job.cron}")
    private String cron;

    @Value("${close.order.comment.job.shard.cnt}")
    private  int shardingTotalCount;

    @Value("${close.order.comment.job.shard.item}")
    private String shardingItemParameters;

    @Value("${close.order.comment.job.params}")
    private String jobParameters;

    @Autowired
    private ZookeeperRegistryCenter regCenter;

    @Bean(initMethod = "init")
    public JobScheduler closeOrderCommentJobScheduler(final CloseOrderCommentJob closeOrderCommentJob) {
        JobListener jobListener = new JobListener();
        return new SpringJobScheduler(closeOrderCommentJob, regCenter, LiteJobDefinition.getLiteJobConfiguration(closeOrderCommentJob.getClass(), cron,
                shardingTotalCount, shardingItemParameters, jobParameters), jobListener);
    }
}
